// pages/Index/shopActive/index.js
const controllers = require('../../controllers/controllerIndex').controller
const app = getApp()

//员工鉴权
const shopStaffHavePower = require("../../../utils/pattern").shopStaffHavePower
Page({

  /**
   * 页面的初始数据
   */
  data: {
    marketNum:0,
    couponNum:0,
    vipNum:0,
    invitationNum:0,
    markettip:'',
    coupontip:'',
    viptip:'',
    relativeNum:0,
    diantype:"",
    explainList:[]
  },
  //跳转到拼团活动页面
  toPing(){
    if(shopStaffHavePower(this.data.power,'PIN')||this.data.diantype==1){
      wx.navigateTo({
        url: '/pages/Index/shopActive/group/index',
      })
    }else{
      wx.showToast({
        icon:"none",
        title: '暂无该权限',
      })
    }
  },
  //跳转到邀请活动页面
  toInvitation(){
    if(shopStaffHavePower(this.data.power,'INVITATION')||this.data.diantype==1){
      wx.navigateTo({
        url: '/pages/Index/shopActive/invitation/index',
      })
    }else{
      wx.showToast({
        icon:"none",
        title: '暂无该权限',
      })
    }
  },
  toCoupon(){
    if(shopStaffHavePower(this.data.power,'COUPON')||this.data.diantype==1){
      wx.navigateTo({
        url: '/pages/Index/shopActive/coupon/index',
      })
    }else{
      wx.showToast({
        icon:"none",
        title: '暂无该权限',
      })
    }
  },
  toDiy(){
    if(shopStaffHavePower(this.data.power,'VIP')||this.data.diantype==1){
      wx.navigateTo({
        url: '/pages/diyActivity/index/index',
      })
    }else{
      wx.showToast({
        icon:"none",
        title: '暂无该权限',
      })
    }
  },
  toRedBagList(){
    if(shopStaffHavePower(this.data.power,'RED')||this.data.diantype==1){
      wx.navigateTo({
        url: '/pages/Index/shopActive/redBag/redBagList',
      })
    }else{
      wx.showToast({
        icon:"none",
        title: '暂无该权限',
      })
    }
  },
  toFriendCards(){
    if(shopStaffHavePower(this.data.power,'VIP')||this.data.diantype==1){
      wx.navigateTo({
        url: '/pages/Index/shopActive/friendCards/friendCards',
      })
    }else{
      wx.showToast({
        icon:"none",
        title: '暂无该权限',
      })
    }
  },

  // 获取活动说明
  getActivityExplain(){
    controllers.getActiveTips({
      types:"17,12,16,11,10,28"
    }).then(res =>{
      res.data.forEach(item=>{
        item.content=item.content.replace(/nowrap/g,"normal")
      })
      this.setData({
        explainList:res.data
      })

    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      diantype:wx.getStorageSync('diantype'),
      power:wx.getStorageSync('power')
    })


    this.getActivityExplain()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
//获取每个活动数量
controllers.getShopActive({
  shopId:wx.getStorageSync('shopId')
}).then(res =>{
  this.setData({
    marketNum:res.data.marketNum,
    couponNum:res.data.couponNum,
    vipNum:res.data.vipNum,
    redNum:res.data.redNum,
    relativeNum:res.data.relativeNum,
    invitationNum:res.data.invitationNum
  })
})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }
})